﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ComLib.ComType
{
    public struct AvailableRange<T> where T : struct, IComparable
    {
        public T Min;
        public T Max;

        public AvailableRange(T min, T max)
        {
            Min = min;
            Max = max;
        }

        public bool Valid()
        {
            if(Min.CompareTo(Max) > 0)
            {
                return false;
            }
            return true;
        }

        public bool InRange(T val)
        {
            if(val.CompareTo(Min) >= 0 && val.CompareTo(Max)<=0)
            {
                return true;
            }
            return false;
        }

        /// <summary>
        /// 数值低于正常范围
        /// </summary>
        /// <param name="val">被比较的数值</param>
        /// <returns></returns>
        public bool IsBelow(T val)
        {
            if (val.CompareTo(Min) < 0)
            {
                return true;
            }
            return false;
        }

        /// <summary>
        /// 数值高于正常范围
        /// </summary>
        /// <param name="val">被比较的数值</param>
        /// <returns></returns>
        public bool IsAbove(T val)
        {
            if (val.CompareTo(Max) > 0)
            {
                return true;
            }
            return false;
        }
    }

}
